from Factors.General import *


def CapCallback(dfData, factorName, params):
    #
    if "IsLn" in params and params["IsLn"] == True:
        dfData[factorName] = np.log(dfData["Close"] * dfData["TotalShares"])
    else:
        dfData[factorName] = dfData["Close"] * dfData["TotalShares"]


def CalcCapFactor(database, instruments, datetime1, datetime2, update=False):
    #
    # CalcDailyFactor(database, instruments, datetime1, datetime2, "Cap", CapCallback, update, fields=["Close", "TotalShares"])

    #
    CalcDailyFactor(database, instruments, datetime1, datetime2, "LnCap", CapCallback, update, params={"IsLn": True},
                    fields=["Close", "TotalShares"], startIndex=0)